package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping ("/destination")
public class DestinationController {
    @Autowired
    private IDestinationService destinationService;
    @RequestMapping ("/list")
    public String list(Model model, @ModelAttribute("qo") DestinationQuery qo,String parentId){
        Page<Destination> page = destinationService.query(qo);
        List<Destination> toasts = destinationService.queryByParentId(parentId);
        model.addAttribute("toasts",toasts);
        model.addAttribute("page",page);
//        int i=1;
        return  "destination/list";
    }
    @RequestMapping ("/updateInfo")
    @ResponseBody
    public Object updateInfo(Destination destination){
        destinationService.updateInfo(destination);
        return  JsonResult.success();
    }
    @RequestMapping ("/delete")
    @ResponseBody
    public Object delete(String id){
        destinationService.delete(id);
        //删除后提示用户,操作成功
        return  JsonResult.success();
    }



    //把目的地设置在新增/编辑页面的下拉框里面
    //根据层次字段deep(3表示是城市)查询目的地对象   就是查询新增/编辑页面的下拉框里面区域对应的城市有哪些
    @RequestMapping ("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep){
        List<Destination> destinations = destinationService.getDestByDeep(deep);
        return  destinations;
    }
//我注释了ajaxGet("/destinations/search",{regionId:regionId},
}
